package R.Service;

import R.Dao.RegDao;
import R.Dao.SickDao;
import R.Entity.Diagnosis;
import R.Entity.Record;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "SickEditServlet", value = "/SickEditServlet")
public class SickEditServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        String card_number = request.getParameter("card_number");//就诊卡号
        String record_number = request.getParameter("record_number");//病历编号
        Diagnosis d=new Diagnosis();
        d.setCard_number(card_number);
        d.setRecord_number(record_number);
        Diagnosis b= SickDao.getD(d);
        HttpSession session=request.getSession();
        session.setAttribute("editD",b);
        response.sendRedirect("/R/sickEdit.jsp");
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        String card_number = request.getParameter("card_number");//就诊卡号
        String record_number = request.getParameter("record_number");//病历编号
        String patient_name = request.getParameter("patient_name");//病人姓名
        String patient_gender = request.getParameter("patient_gender");//病人性别
        String doctor_number = request.getParameter("doctor_number");//医生编号
        String doctor_name = request.getParameter("doctor_name");//医生姓名
        String doctor_title = request.getParameter("doctor_title");//医生职称
        String drug_name = request.getParameter("drug_name");//药品名称
        String drug = request.getParameter("drug");//药品规格
        String drug_quantity = request.getParameter("drug_quantity");//药品数量
        String diagnosis_result = request.getParameter("diagnosis_result");//诊断结果
        String treatment_method = request.getParameter("treatment_method");//治疗方法
        String department_name = request.getParameter("department_name");//就诊科室
        String diagnosis_time = request.getParameter("diagnosis_time");//诊断时间
        //创建实体类
        Diagnosis d=new Diagnosis();
        d.setCard_number(card_number);
        d.setRecord_number(record_number);
        d.setPatient_name(patient_name);
        d.setPatient_gender(patient_gender);
        d.setDoctor_number(doctor_number);
        d.setDoctor_name(doctor_name);
        d.setDoctor_title(doctor_title);
        d.setDrug_name(drug_name);
        d.setDrug(drug);
        d.setDrug_quantity(drug_quantity);
        d.setDiagnosis_result(diagnosis_result);
        d.setTreatment_method(treatment_method);
        d.setDepartment_name(department_name);
        d.setDiagnosis_time(diagnosis_time);
        int sta = SickDao.UpdateD(d);
        if (sta>0){
            response.sendRedirect("SickShowAll");
        }else {
            response.sendRedirect("/R/sickEdit.jsp");
        }
    }
}
